package com.qf.service.impl;

import com.qf.dao.StuDao;
import com.qf.dao.impl.StuDaoImpl;
import com.qf.pojo.PageBean;
import com.qf.pojo.Stu;
import com.qf.service.StuService;

import java.util.List;

public class StuServiceImpl implements StuService {
    private StuDao stuDao=new StuDaoImpl();
    @Override
    public Stu login(String stuname, String pwd) {
        Stu login = stuDao.login(stuname, pwd);
        if(login==null){
            throw new RuntimeException("用户不存在");
        }
        if(!login.getPwd().equalsIgnoreCase(pwd)){
            throw new RuntimeException("密码错误");
        }
        return login;
    }

    @Override
    public void addStu(Stu stu) {
        stuDao.insertStu(stu);

    }

    @Override
    public List<Stu> findAll(int page_num, int page_size) {
        return stuDao.selectAll(page_size,page_num);
    }


    @Override
    public void remove(int id) {
        stuDao.delete(id);
    }

    @Override
    public void modify(Stu stu) {
        stuDao.update(stu);
    }

    @Override
    public PageBean<Stu> findByPage(int pageNum, int pageSize) {
        long totalSize=stuDao.selectCount();
        List<Stu> data=stuDao.selectByPage(pageNum,pageSize);
        PageBean<Stu> pageBean=new PageBean<Stu>(pageSize,pageNum,totalSize,data);
        return pageBean;
    }
}
